﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Lucy.Engine.Framework.Components
{
    public class SpriteRendererComponent : Component
    {
        public Texture2D Texture { get; private set; }
        public Point Size { get; set; }
        public string Name { get; set; }

        public SpriteRendererComponent(Texture2D texture)
        {
            Texture = texture;
            Size = new Point(Texture.Width, Texture.Height);
            Name = "SpriteRenderer";
        }

        public override void OnUpdate(float elapsed, GameObject gameObject)
        {
            
        }

        public override void OnRender(SpriteBatch spriteBatch, GameObject gameObject)
        {
            Vector2 scale = new Vector2(Size.X/(float) Texture.Width, Size.Y/(float) Texture.Height);
            spriteBatch.Draw(Texture, gameObject.Position, null, Color.White, gameObject.Rotation, Vector2.Zero, scale, SpriteEffects.None, 0);
        }

        public override IEnumerable<string> GetProperties()
        {
            yield return "Size";
            yield return "Texture";
        }

        public override void SetValue(string propertyName, string value)
        {
            switch (propertyName)
            {
                case "Size":

                    break;
            }
        }

        public override string GetValue(string propertyName)
        {
            switch (propertyName)
            {
                case "Size":
                    return string.Format("{0},{1}", Size.X, Size.Y);
            }

            return String.Empty;
        }
    }
}
